#ifndef THREAD_H
#define THREAD_H 1

#include "main.h"
#include <pthread.h>
#include <stdint.h>

#ifndef MAX_THREADS
# define MAX_THREADS 4
#endif

typedef void* pthread_any_t;
typedef void *(*start_routine_t) (void *);

typedef struct __ncattr__ threadpool
{
  pthread_t thrd;
  const pthread_attr_t *attr;
  pthread_any_t data;
} threadpool_t;


int
get_pthread_count(void);

int
get_thread_num(void);

threadpool_t *
get_thread_data(const uint8_t tidx);

threadpool_t *
get_this_thread_data(void);

void
init_threads(const uint8_t max_threads);

void
free_threads(void);

int
create_thread(start_routine_t cb, void *arg);

int
threads_wait(int data_size);

void
threads_mtx_lock(void);

void
threads_mtx_unlock(void);

#endif
